from Utils.command.command import Command
import CloudEngine.core.VTActor as VTActorMod
import vtkmodules.all as vtk


class CreatePointCommand(Command):
    def __init__(self, vertexes, options):
        self.vertexes = vertexes
        self.options = options
        self.actor = self.execute()

    def execute(self):
        points = vtk.vtkPoints()
        for item in self.vertexes:
            points.InsertNextPoint(item.get("XYZ"))
        poly_data = vtk.vtkPolyData()
        poly_data.SetPoints(points)

        vertex_glyph_filter = vtk.vtkVertexGlyphFilter()
        vertex_glyph_filter.SetInputData(poly_data)
        vertex_glyph_filter.Update()
        actor = VTActorMod.VTActor(poly_data, self.options)
        actor.mapper.SetInputConnection(vertex_glyph_filter.GetOutputPort())
        actor.instance.GetProperty().SetColor(1, 0, 0)  # 设置顶点颜色为红色
        actor.instance.GetProperty().SetPointSize(5)  # 设置顶点大小为5
        actor.set_render_type("POINTS")

        return actor
